//
//  SEInquiryModel.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/4/20.
//

import HandyJSON

/// 问诊流程状态
/// 0初始待支付,1支付成功后台发起,2医生同意,3患者收到医生同意,4医生结束发,5患者同意,6医生拒绝,7患者拒绝结束,8患者取消,9已评价
enum SEInquiryChangeStatus: String, HandyJSONEnum, Codable {
    case waitPay = "0", waitConfirm = "1", confirming = "2", confirmed = "3", waitEnd = "4", confirmEnd = "5", rejected = "6", rejectEnd = "7", cancel = "8", commented = "9"
    
    var hudMessage: String? {
        switch self {
        case .waitConfirm:  return "您有一条待确认的问诊"
        case .rejectEnd:    return "患者想继续咨询"
        case .confirmEnd:   return "患者确认结束咨询"
        default: return nil
        }
    }
    
    var statusText: String? {
        switch self {
        case .waitEnd:    return "等待患者确认..."
        case .confirmEnd: return "患者已同意"
        case .rejectEnd:  return "患者已拒绝"
        default:          return nil
        }
    }
    
    var statusTextColor: UIColor? {
        switch self {
        case .waitEnd:    return Asset.textDark.color
        case .confirmEnd: return Asset.main.color
        case .rejectEnd:  return Asset.warn.color
        default:          return nil
        }
    }
}

/// 1 - 进行中的问诊 2 - 历史问诊
enum SEInquiryType: Int, HandyJSONEnum, Codable {
    case current = 1, history
    
    var chatType: SEChatType { .onlineInquiry }

    var msgType: String { "single" }
    
    var userdefaults: String {
        switch self {
        case .current: return "currentInquiry"
        case .history: return "historyInquiry"
        }
    }
}

/// 问诊、导诊状态
/// 问诊状态（0-初始化待支付, 1-患者发起，2-进行中，3-结束发起，4-结束，5-医生拒绝，6-患者拒绝结束，7-已取消）
enum SEInquiryStatus: Int, HandyJSONEnum, Codable {
    case waitPay = 0, reserve, processing, waitFinish, finish, rejectStart, rejectFinish, cancel, unknown = -1

    var title: String {
        switch self {
        case .waitPay: return "待支付"
        case .reserve: return "待接诊"
        case .processing, .waitFinish, .rejectFinish: return "进行中"
        case .finish: return "已结束"
        case .rejectStart, .cancel: return "已取消"
        case .unknown: return "未知状态"
        }
    }

    var titleColor: UIColor {
        switch self {
        case .waitPay: return UIColor(hex: "#F7B500")
        case .reserve, .processing, .waitFinish, .rejectFinish: return UIColor(hex: "#4ABC90")
        default: return UIColor(hex: "#CCCCCC")
        }
    }

}

enum SEPatientFileAuthorizedStatus: String, HandyJSONEnum, Codable {
    case unauthorized = "1", authorized = "2", refuse = "3"
    
    var statusText: String? {
        switch self {
        case .unauthorized: return "等待患者同意..."
        case .authorized:   return "患者已同意"
        case .refuse:       return "患者已拒绝"
        }
    }
    
    var statusTextColor: UIColor {
        switch self {
        case .unauthorized: return Asset.textDark.color
        case .authorized:   return Asset.main.color
        case .refuse:       return Asset.warn.color
        }
    }
    
    var message: String? {
        switch self {
        case .unauthorized: return nil
        case .authorized:   return "患者同意查看就诊档案"
        case .refuse:       return "患者拒绝查看就诊档案"
        }
    }
}

struct SEInquiryModel: HandyJSON {
    var pageNum: Int = 0
    var pageSize: Int = 0
    var total: Int = 0
    var totalPage: Int = 0
    var list: [SEInquiryDetail]?
}

struct SEInquiryDetail: HandyJSON, Codable {
    /// 1-当前问诊 2-历史问诊
    var type: SEInquiryType = .current
    
    var id: String?
    var creator: String?        // 发送者id
    var creatorName: String?    // 发送者名称
    var createTime: String?
    var updateTime: String?
    var `operator`: String?
    var isDeleted: Int = 0
    
    var patientId: String?
    var patientName: String?
    var patientSex: Int = 0
    var patientAge: String?
    var patientPhone: String?
    var patientIdcard: String?

    var hospitalName: String?
    var hospitalId: String?

    var doctorId: String?
    var doctorName: String?
    var deptName: String?
    var jobTitle: String?
    var receiver: String?       // 接收者id
    var receiverName: String?   // 接收者名称
    var illness: String?
    var isAllergic: Int = 1
    var allergicContent: String?
    var pastHistory: String?
    var urlRelation: String?
    var status: SEInquiryStatus = .unknown
    var dealStatus: SEInquiryChangeStatus = .waitPay
    var unReadCount: Int = 0
    var lastReadTime: String?
    var msgType: SEChatMessageType = .text
    var content: String?
    var picList: [SEUploadFileModel]?
    
    var result: String?                 // 诊断结果
    var proposal: String?               // 医嘱意见
    
    var userPhoto: String?
    var otherPhoto: String?
    
    var orderId: String?
    
    var authorizationStatus: SEPatientFileAuthorizedStatus = .unauthorized
    
    var leftTime: Int = 0       // 结束倒计时（毫秒）
}

struct DoctorCountsDtoModel: HandyJSON {
    /// 患者数量
    var patientCount: String = "0"
    /// 评论数
    var commentCount: String = "0"
    /// 粉丝数量
    var followCount: String = "0"
}
